package com.mcptt.config.user.profile.sub.sub;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;
import com.mcptt.config.user.profile.sub.sub.sub.EmergencyCall;
import com.mcptt.config.user.profile.sub.sub.sub.PrivateCallURI;

public class PrivateCall
{
	public static final String Name = "PrivateCall";
	public static final String Name_PrivateCallList = "PrivateCallList";
	
	private List<PrivateCallURI> privateCallList = null;
	private EmergencyCall emergencyCall = null;

	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_PrivateCallList))
			{
				parseSubElem(subElem);
			}
			else if(name.equals(EmergencyCall.Name))
			{
				emergencyCall = new EmergencyCall();
				emergencyCall.parse(subElem);
			}
		}  
	}
	
	public void parseSubElem(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		privateCallList = new Vector<PrivateCallURI>();
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(PrivateCallURI.Name))
			{
				PrivateCallURI privateCallURI = new PrivateCallURI();
				privateCallURI.parse(subElem);
				privateCallList.add(privateCallURI);
			}
		}  
	}
	
	public List<PrivateCallURI> getPrivateCallList()
	{
	    return privateCallList;
	}
	public EmergencyCall getEmergencyCall() {
		return emergencyCall;
	}

	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		
		strBuf.append("    ").append("<").append(Name_PrivateCallList).append(">").append("\r\n");
		for(Iterator<PrivateCallURI> itor = privateCallList.iterator();itor.hasNext();)
		{
			strBuf.append(itor.next()).append("\r\n");
		}
		strBuf.append("    ").append("</").append(Name_PrivateCallList).append(">").append("\r\n");
		
		strBuf.append(emergencyCall);

		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
